package com.huawei.hwid.api.common;

import android.content.Context;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.core.helper.handler.ErrorStatus;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public abstract class b implements Runnable {
    protected final CountDownLatch a = new CountDownLatch(1);
    protected final AtomicBoolean b = new AtomicBoolean(false);
    protected Context c;

    abstract void a(ErrorStatus errorStatus);

    abstract void b();

    protected b(Context context) {
        this.c = context;
    }

    public void run() {
        b();
        try {
            if (!this.a.await(12000, TimeUnit.MILLISECONDS)) {
                c();
            }
        } catch (InterruptedException e) {
            e.b("AIDLTask", "execute await InterruptedException", true);
            c();
        }
    }

    private void c() {
        if (!this.b.get()) {
            this.b.set(true);
            a(null);
            a();
        }
    }

    protected void a() {
        e.b("AIDLTask", "finishTask", true);
        a a = a.a(this.c);
        if (a != null) {
            a.b();
            this.a.countDown();
            this.b.set(true);
        }
    }
}
